<template>
  <div class="panel-tab__content">
    <el-form v-model="bpmn.bpmnData" size="mini" label-width="100px">
      <el-form-item label="调用指令" required>
        <el-input v-model="bpmn.bpmnData.callCmd" @change="updateBaseInfo('callCmd')" />
      </el-form-item>
      <el-form-item label="业务标签" required>
        <el-input v-model="bpmn.bpmnData.processLabel" @change="updateBaseInfo('processLabel')" placeholder="用于流程分类" />
      </el-form-item>
      <el-form-item label="主业务模型" required>
        <el-popover
            placement="bottom"
            title="数据模型选择"
            width="600"
            trigger="click"
            v-model="mainVisible">
          <model-list select @rowSelect="(row) => {handleSelect(row,'callMain')}"></model-list>
          <el-input  slot="reference" v-model="bpmn.bpmnData.mainModel" @click="()=>{mainVisible = true;}" placeholder="用于主业务数据查询和更新" />
        </el-popover>
      </el-form-item>
      <el-form-item label="主业务主键" required>
        <el-input v-model="bpmn.bpmnData.mainPrimary" @change="updateBaseInfo('mainPrimary')" disabled />
      </el-form-item>
      <el-form-item label="主业务展示" required>
        <el-input v-model="bpmn.bpmnData.mainLabel" @change="updateBaseInfo('mainLabel')" placeholder="主业务展示字段" />
      </el-form-item>
      <el-form-item label="子业务模型" required>
        <el-popover
            placement="bottom"
            title="数据模型选择"
            width="600"
            trigger="click"
            v-model="selectVisible">
          <model-list select @rowSelect="(row) => {handleSelect(row,'callSub')}"></model-list>
          <el-input slot="reference" v-model="bpmn.bpmnData.subModel" @click="()=>{selectVisible = true;}" placeholder="用于子业务数据查询和更新" />
        </el-popover>
      </el-form-item>
      <el-form-item label="子业务主键" required>
        <el-input v-model="bpmn.bpmnData.subPrimary" @change="updateBaseInfo('subPrimary')" disabled />
      </el-form-item>
      <el-form-item label="子业务展示" required>
        <el-input v-model="bpmn.bpmnData.subLabel" @change="updateBaseInfo('subLabel')" placeholder="支持${xx}模板" />
      </el-form-item>
      <el-form-item label="子业务过滤">
        <el-input type="textarea" :rows="8" v-model="bpmn.bpmnData.subFilter" @change="updateBaseInfo('subFilter')" placeholder="子业务过滤" />
      </el-form-item>
    </el-form>
  </div>
</template>
/**
* @description
* @author mao
* @time: 2021/8/12 3:13 下午
**/
<script>
import ModelList from "@/views/system/model/ModelList";
export default {
  name: 'PanelProcess',
  components: {ModelList},
  inject: {
    bpmn: {
      from: 'bpmn'
    },
    setExtensions: {
      from: 'setExtensions'
    }
  },
  provide() {
    return {
      platform: this.platform
    }
  },
  data() {
    return {
      platform: { design: true },
      mainVisible: false,
      selectVisible: false
    }
  },
  methods: {
    updateBaseInfo(key) {
      const config = {  }
      config[key] = this.bpmn.bpmnData[key]
      this.setExtensions(config)
    },
    handleSelect(row, selectType) {
      const { callCmd, modelPrimary } = row
      if (!callCmd) {
        return
      }
      if (selectType === 'view') {
        this.$set(this.bpmn.bpmnData, 'startView', callCmd)
        this.updateBaseInfo('startView')
      } else {
        if (selectType === 'callMain') {
          this.$set(this.bpmn.bpmnData, 'mainModel', callCmd)
          this.updateBaseInfo('mainModel')
          this.$set(this.bpmn.bpmnData, 'mainPrimary', modelPrimary)
          this.updateBaseInfo('mainPrimary')
          this.mainVisible = false
        } else {
          this.$set(this.bpmn.bpmnData, 'subModel', callCmd)
          this.updateBaseInfo('subModel')
          this.$set(this.bpmn.bpmnData, 'subPrimary', modelPrimary)
          this.updateBaseInfo('subPrimary')
          this.selectVisible = false
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
